#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>



typedef struct {
  double x;
  double y;
  double z;
} Vector;

typedef struct {
  double x, y, z;
} Point;

typedef struct {
  Vector point;
  Vector vector;
} Ray;



typedef struct {
  Vector center;
  float radius;
} Sphere;



double dot(Vector v1, Vector v2) {
  return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);
};

double magnitude(Vector v1) {
  double d, s;
  d = dot(v1, v1);
  s = sqrt(d);
  return s;
};

Vector addV(Vector v1, Vector v2) {
  Vector v;
  v.x = v1.x + v2.x;
  v.y = v1.y + v2.y;
  v.z = v1.z + v2.z;
  return v;
};

Vector addVnP(Vector v1, Point p1) {
  Vector v;
  v.x = v1.x + p1.x;
  v.y = v1.y + p1.y;
  v.z = v1.z + p1.z;
  return v;
};

Vector sub(Vector v1, Vector v2) {
  Vector v;
  v.x = v1.x - v2.x;
  v.y = v1.y - v2.y;
  v.z = v1.z - v2.z;
  return v;
};

Vector scale(Vector v1, double f) {
  Vector v;
  v.x = v1.x * f;
  v.y = v1.y * f;
  v.z = v1.z * f;
  return v;
};

Vector cross(Vector v1, Vector v2) {
  Vector v;
  v.x = v1.y * v2.z - v1.z * v2.y;
  v.y = v1.z * v2.x - v1.x * v2.z;
  v.z = v1.x * v2.y - v1.y * v2.x;
  return v;
};

Vector normalized(Vector v1){
  Vector v;
  v = scale(v1, 1.0 / vec_magnitude(v1));
  return v;
};

Vector negated(Vector v1){
  Vector v;
  v = scale(v1, -1);
};

bool equal(Vector v1, Vector v2){
  return (v1.x == v2.x)  && 
    (v1.y == v2.y)  && 
    (v1.z == v2.z) ;
    
};

Vector reflectThrough(Vector v, Vector n){
  Vector sb;
  sb = sub(v, vec_scale(vec_scale(n, vec_dot(v, n)), 2.0));
  return sb;
};



Point pnt_add(Point p1, Point p2){
  Point p;
  p.x = p1.x + p2.x;
  p.y = p1.y + p2.y;
  p.z = p1.z + p2.z;

  return p;
};

Point pnt_sub(Point p1, Point p2){
  Point p;
  p.x = p1.x - p2.x;
  p.y = p1.y - p2.y;
  p.z = p1.z - p2.z;

  return p;
};



double sph_intersectionTime(Sphere s1, Ray r1){
  Vector cp;
  double v, discriminant;
  cp = sub(s1.center, r1.point);
  v = dot(cp, r1.vector);
  discriminant = (s1.radius * s1.radius) - (dot(cp,cp)-v*v);
  if (discriminant < 0)
    return 0.0;
  else
    return v - sqrt(discriminant);
};

Vector sph_normalAt(Sphere s1, Vector p){
  return normalized(vec_sub(p, s1.center));
};



int main(){
  Vector v, v2;
  Vector p, p1, p2;

  v.x = 25.0;
  v.y = 27.0;
  v.z = 27.0;


  printf("%f %f %f,", v.x, v.y, v.z);
  v2 = normalized(v);
  v2 = sub(v2, v); 
  printf("%f %f %f,", v2.x, v2.y, v2.z);

  v2 = reflectThrough(v, v2);
  printf("%f %f %f,", v2.x, v2.y, v2.z);




  p1.y = 25;
  p2 = addV(p,p1);
  printf("%f",p1.y);




  return 0;


}















